from django import forms
from .models import ImageStorage


class OneImageUploadForm(forms.ModelForm):
    class Meta:
        model = ImageStorage  # 对应的Model中的类
        exclude = ['file_key', 'create_time', 'is_delete']

    def get_errors(self):
        errors = self.errors.get_json_data()
        new_errors = {}
        for key, message_dicts in errors.items():
            messages = []
            for message in message_dicts:
                messages.append(message['message'])
            new_errors[key] = messages
        return new_errors
